//
//  ShowHud.m
//  OpenDoor
//
//  Created by M&M on 15/6/2.
//  Copyright (c) 2015年 CNMOBI. All rights reserved.
//

#import "ShowHud.h"

@implementation ShowHud

+(void)showHUD:(NSString *)textStr andWithView:(UIView *)showView
{
    MBProgressHUD *_showHud = [[MBProgressHUD alloc] initWithView:showView];
    [showView addSubview:_showHud];
    _showHud.tag = 10000;
    
    if (![textStr isEqualToString:@""]&&textStr !=nil) {
        _showHud.labelText = textStr;
    }
    
    
    
    [_showHud show:YES];
    

}

+ (void)RemoveHUDFromView:(UIView *)showView
{
    MBProgressHUD *Hud = (MBProgressHUD *)[showView viewWithTag:10000];
    [Hud removeFromSuperview];
    
}

+(void)showSuccess:(NSString *)successStr andWithView:(UIView *)showView
{
    if ((MBProgressHUD *)[showView viewWithTag:10001]) {
        return;
    }
    MBProgressHUD *_showHud = [[MBProgressHUD alloc] initWithView:showView];
    [showView addSubview:_showHud];
    _showHud.tag = 10001;
    
    _showHud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];
    
    // Set custom view mode
    _showHud.mode = MBProgressHUDModeCustomView;
    
    _showHud.labelText = successStr;

    [_showHud show:YES];
    
    [self performSelector:@selector(HideSuccessFromView:) withObject:showView afterDelay:1];
}
+(void)showFailed:(NSString *)failStr andWithView:(UIView *)showView
{
    if ((MBProgressHUD *)[showView viewWithTag:10001]) {
        return;
    }
    MBProgressHUD *_showHud = [[MBProgressHUD alloc] initWithView:showView];
    [showView addSubview:_showHud];
    _showHud.tag = 10001;
    
    _showHud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"337x-Checkmark.png"]];
    
    // Set custom view mode
    _showHud.mode = MBProgressHUDModeCustomView;
    
    _showHud.labelText = failStr;
    
    [_showHud show:YES];
    
    [self performSelector:@selector(HideSuccessFromView:) withObject:showView afterDelay:1];
}
+ (void)HideSuccessFromView:(UIView *)showView
{
    
    MBProgressHUD *Hud = (MBProgressHUD *)[showView viewWithTag:10001];

    [Hud hide:YES];

    
    [self performSelector:@selector(RemoveSuccessFromView:) withObject:showView afterDelay:1];
}
+ (void)RemoveSuccessFromView:(UIView *)showView
{
    
    MBProgressHUD *Hud = (MBProgressHUD *)[showView viewWithTag:10001];
    
    [Hud removeFromSuperview];
    
}
@end
